package com.xls.future.fragment;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xls.future.R;
import com.xls.future.adapter.VideoListAdapter;
import com.xls.future.entity.VideoInfo;
import com.xls.future.utils.LogUtil;
import com.xls.future.view.FindView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Optional;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/8/22.
 */

public class FindFragment extends BaseFragment implements FindView{


    private static final String TAG = "FindFragment";

    /*@BindView(R.id.title)
    TextView title;*/
    Unbinder unbinder;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout swipeLayout;
    private Handler mHandler;
    private VideoListAdapter adapter;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.d("xls", "FindFragment onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("xls", "FindFragment onCreate");
        mHandler = new Handler();
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d("xls", "FindFragment onCreateView");
        View view = inflater.inflate(R.layout.fragment_find, container, false);
        unbinder = ButterKnife.bind(this, view);
        initViews();
        return view;
    }

    private void initViews() {
//        title.setText(R.string.find);
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                //下拉刷新
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeLayout.setRefreshing(false);
                    }
                },1000);
            }
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
        adapter = new VideoListAdapter();
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d("xls", "FindFragment onActivityCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("xls", "FindFragment onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d("xls", "FindFragment onResume");
        if(isFirstVisible){
            LogUtil.d("xiong","FindFragment 第一次可见");

        }
    }

    @Override
    public void bindDataToList(List<VideoInfo> videoInfos) {

    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d("xls", "FindFragment onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("xls", "FindFragment onStop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d("xls", "FindFragment onDestroyView");
        unbinder.unbind();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("xls", "FindFragment onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d("xls", "FindFragment onDetach");
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        Log.d("xls", "FindFragment onHiddenChanged : " + hidden);
        if (hidden) {
            //隐藏
            isFirstVisible = false;
        } else {
            //显示
            LogUtil.d("xiong","FindFragment 显示");
        }
    }
}
